package com.epam.training.domain;

import java.io.Serializable;
import java.math.BigDecimal;

import javax.persistence.*;

import java.util.List;

/**
 * The persistent class for the insurance database table.
 * 
 */
@Entity
@Table(name = "insurance")
@NamedQuery(name = "Insurance.findAll", query = "SELECT i FROM Insurance i")
public class Insurance implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@SequenceGenerator(name = "INSURANCE_INSURANCEID_GENERATOR", sequenceName = "INSURANCE_ID_SEQ", initialValue = 1, allocationSize = 1)
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "INSURANCE_INSURANCEID_GENERATOR")
	@Column(name = "insurance_id", insertable = false, updatable = false, unique = true, nullable = false)
	private Integer insuranceId;

	@Column(length = 2147483647)
	private String description;

	@Column(length = 20)
	private String name;

	@Column(precision = 131089)
	private BigDecimal price;

	// bi-directional many-to-one association to Bookingitem
	@OneToMany(mappedBy = "insurance")
	private List<BookingItem> bookingItems;

	public Insurance() {
	}

	public Integer getInsuranceId() {
		return this.insuranceId;
	}

	public void setInsuranceId(Integer insuranceId) {
		this.insuranceId = insuranceId;
	}

	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public BigDecimal getPrice() {
		return this.price;
	}

	public void setPrice(BigDecimal price) {
		this.price = price;
	}

	public List<BookingItem> getBookingItems() {
		return this.bookingItems;
	}

	public void setBookingitems(List<BookingItem> bookingitems) {
		this.bookingItems = bookingitems;
	}

	public BookingItem addBookingitem(BookingItem bookingitem) {
		getBookingItems().add(bookingitem);
		bookingitem.setInsurance(this);

		return bookingitem;
	}

	public BookingItem removeBookingitem(BookingItem bookingItem) {
		getBookingItems().remove(bookingItem);
		bookingItem.setInsurance(null);

		return bookingItem;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((bookingItems == null) ? 0 : bookingItems.hashCode());
		result = prime * result
				+ ((description == null) ? 0 : description.hashCode());
		result = prime * result
				+ ((insuranceId == null) ? 0 : insuranceId.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + ((price == null) ? 0 : price.hashCode());
		return result;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Insurance other = (Insurance) obj;
		if (bookingItems == null) {
			if (other.bookingItems != null)
				return false;
		} else if (!bookingItems.equals(other.bookingItems))
			return false;
		if (description == null) {
			if (other.description != null)
				return false;
		} else if (!description.equals(other.description))
			return false;
		if (insuranceId == null) {
			if (other.insuranceId != null)
				return false;
		} else if (!insuranceId.equals(other.insuranceId))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (price == null) {
			if (other.price != null)
				return false;
		} else if (!price.equals(other.price))
			return false;
		return true;
	}
}
